" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.

runtime! debian.vim

" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"filetype plugin indent on

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd		" Show (partial) command in status line.
"set showmatch		" Show matching brackets.
"set ignorecase		" Do case insensitive matching
"set smartcase		" Do smart case matching
"set incsearch		" Incremental search
"set autowrite		" Automatically save before commands like :next and :make
"set hidden		" Hide buffers when they are abandoned
"set mouse=a		" Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif
" <<<<<< (from /etc/vim/vimrc)


" Auto load for first time uses
if empty(glob('~/.vim/autoload/plug.vim'))
	silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
				\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif


" King add vimrc info
colorscheme desert 		" elflord ron peachpuff default 设置配色,vim自带的配色方案保存在/usr/share/vim/vim74/colors目录下

" detect file type
filetype on
filetype plugin on
filetype indent on

" 设定文件编码类型,彻底解决中文编码问题
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936,iso8859-2
" set fenc=utf-8 	" defaut fileencoding
set fencs=utf-8,gb18030,gbk,gb2312,cp936,ucs-bom,euc-jp,default,latin1,iso8859-2



set ignorecase 		" 搜索模块里忽略大小写
set smartcase 		" 如果搜索模式包含大写字符,不使用'ignorecase'选项.只有在输入搜索模式并且打开'ignorecase'选项时才会使用.
set autowrite 		" 自动把内容写回文件:如果文件被修改过,在每个:next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, :make, CTRL-]和CTRL-^命令时进行;用:buffer, CTRL-O, CTRL-I, '{A-Z0-9}' or '{A-Z0-9}'命令转到别的文件时亦然.
set autoindent 		" 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
set smartindent 	" 智能对齐方式
set tabstop=4 		" 设备制表符(tab键)的宽度
set softtabstop=4 	" 设置软制表符的宽度
set shiftwidth=4 	" (自动)缩进使用4个空格
set cindent			" 使用C/C++语言的自动缩进方式
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s		" 设置C/C++语言的具体缩进方式
"set backspace=2	" 设置退格键可用
set showmatch		" 设置匹配模式,显示匹配的括号
set linebreak		" 整词换行
"set whichwrap=b,s,<,>,[,]	" 光标从行首和行末可以跳到另一行去
"set hidden			" Hide buffer when the are abandoned
set mouse=a			" Enable mouse usage (all modes)
set number			" Enable line number
"set previewwindow	" 标识预览窗口
set history=500		" set command history 500 历史记录500条


" --状态行设置--
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}		" 状态行显示内容
set laststatus=2	" 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行
set ruler		" 标尺,用于显示光标位置的行号和列号,逗号分隔.每个窗口都有自己的标尺.如果窗口有状态行,标尺在那里显示,否则,它显示在屏幕的最后一行上

" --命令行设置--
set showcmd		" 命令行显示输入的命令
set showmode		" 命令行显示vim当前模式

" --find setting--
set incsearch		" 输入字符串就显示匹配点
set hlsearch

" -- fold setting--
"set foldenable		" 允许折叠
set foldmethod=syntax	" 用语法高亮来定义折叠
set foldlevel=100	" 启动vim时不要自动折叠代码
set foldcolumn=5	" 设置折叠栏宽度

" --ctags setting--
" 按下F5重新生成tag文件,并更新taglist
" ctags -I __THROW -I __attribute__ -I __attribute_pure__ -I __nonnull --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+ialS --extra=+q -R /usr/include /usr/local/include
map <F5> :!ctags -R --c++-kinds=+p --fields=+isS --extra=+q .<CR><CR> :TlistUpdate<CR>
imap <F5> <ESC>:!ctags -R --c++-kinds=+p --fields=+isS --extras=+q .<CR><CR> :TlistUpdate<CR>
" set tags+=/home/jin/.vim/systags/tags	


" -- cscope setting --
map <F4> :cs kill -1<cr>:!cscope -Rbq<cr>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
imap <F4><ESC> :cs kill -1<cr>:!cscope -Rbq<cr>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>

if has("cscope")
	set csprg=/usr/bin/cscope		" 指定用来执行cscope的命令
	set csto=0						" 设置cstag命令查找次序:0先找cscope数据库再标签文件;1先找标签文件再找cscope数据库
	set cst							" 同时搜索cscope数据库和标签文件
	set nocsverb
	set cscopequickfix=s-,c-,d-,i-,t-,e-		" 使用QuickFix窗口来显示cscope查找结果
	" add any database in current directory
	if filereadable("cscope.out")	" 若当前目录下存在cscope数据库,添加该数据库到vim
		cs add cscope.out
	" else add database pointed to by environment
	elseif $CSCOPE_DB != ""
		cs add $CSCOPE_DB
	endif
	set csverb
	" s: C语言符号 g:定义 d:这个函数调用的函数
	" c:调用这个函数的函数 t:文本 e:egrep模式 f:文件
	" i:include本文件的文件
	nmap <C-_>s :cs find s <C-R>=expand("cword")<CR><CR>:copen<CR>
	nmap <C-_>g :cs find g <C-R>=expand("cword")<CR><CR>:copen<CR>
	nmap <C-_>c :cs find c <C-R>=expand("cword")<CR><CR>:copen<CR>
	nmap <C-_>t :cs find t <C-R>=expand("cword")<CR><CR>:copen<CR>
	nmap <C-_>e :cs find e <C-R>=expand("cword")<CR><CR>:copen<CR>
	nmap <C-_>f :cs find f <C-R>=expand("cfile")<CR><CR>:copen<CR>
	nmap <C-_>i :cs find i ^<C-R>=expand("cfile")<CR>$<CR>:copen<CR>
	nmap <C-_>d :cs find d <C-R>=expand("cword")<CR><CR>:copen<CR>
endif






" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" c-support
Plug 'WolfgangMehner/c-support'

" Auto Complete (coc.nvim)
" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}

" File navigation
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" taglist - Source Code Browser plugin for Vim
"Plug 'yegappan/taglist'
Plug 'liuchengxu/vista.vim'



" Undo Tree
"Plug 'mbbill/undotree'

" Markdown
"Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
"Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle', 'for': ['text', 'markdown', 'vim-plug'] }
"Plug 'mzlogin/vim-markdown-toc', { 'for': ['gitignore', 'markdown', 'vim-plug'] }
"Plug 'dkarter/bullets.vim'




" Initialize plugin system
call plug#end()



" <<<<<<<<<< 
" vim-airline
"
let g:airline_powerline_fonts = 0
" let g:airline_theme='dracula'

" Show buffers on top
"let g:airline#extensions#tabline#enabled=1
" Show buffers count
let g:airline#extensions#tabline#buffer_nr_show=1
" >>>>>>>>>>


" >>>>>>>>>>
" Example vim configuration (coc.nvim)
let g:coc_global_extensions = [
			\ 'coc-json',
			\ 'coc-clangd',
			\ 'coc-pyright']

" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
"set nobackup
"set nowritebackup

" Give more space for displaying messages.
"set cmdheight=2

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
	" Recently vim can merge signcolumn and number column into one
	set signcolumn=number
else
	set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
			\ pumvisible() ? "\<C-n>" :
			\ <SID>check_back_space() ? "\<TAB>" :
			\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
	let col = col('.') - 1
	return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
	inoremap <silent><expr> <c-space> coc#refresh()
else
	inoremap <silent><expr> <c-@> coc#refresh()
endif

" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
			\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation.
" nmap <silent> gd <Plug>(coc-definition)
nmap <silent> df <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
	if (index(['vim','help'], &filetype) >= 0)
		execute 'h '.expand('<cword>')
	elseif (coc#rpc#ready())
		call CocActionAsync('doHover')
	else
		execute '!' . &keywordprg . " " . expand('<cword>')
	endif
endfunction

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
	autocmd!
	" Setup formatexpr specified filetype(s).
	autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
	" Update signature help on jump placeholder.
	autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac  <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf  <Plug>(coc-fix-current)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
	nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
	nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
	inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
	inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
	vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
	vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" NeoVim-only mapping for visual mode scroll
" Useful on signatureHelp after jump placeholder of snippet expansion
if has('nvim')
	vnoremap <nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#nvim_scroll(1, 1) : "\<C-f>"
	vnoremap <nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#nvim_scroll(0, 1) : "\<C-b>"
endif

" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>
" <<<<<<<<<<




" >>>>>>>>>>
" fzf.vim
"
" global options
" This is the default option:
"   - Preview window on the right with 50% width
"   - CTRL-/ will toggle preview window.
" - Note that this array is passed as arguments to fzf#vim#with_preview function.
" - To learn more about preview window options, see `--preview-window` section of `man fzf`.
let g:fzf_preview_window = ['right:30%', 'ctrl-/']

" Preview window on the upper side of the window with 40% height,
" hidden by default, ctrl-/ to toggle
"let g:fzf_preview_window = ['up:40%:hidden', 'ctrl-/']

" Empty value to disable preview window altogether
"let g:fzf_preview_window = []


" command-local options
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'

let g:fzf_layout = { 'window': { 'width': 0.5, 'height': 0.4 } }


function! s:list_buffers()
	redir => list
	silent ls
	redir END
	return split(list, "\n")
endfunction

function! s:delete_buffers(lines)
	execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
endfunction

command! BD call fzf#run(fzf#wrap({
			\ 'source': s:list_buffers(),
			\ 'sink*': { lines -> s:delete_buffers(lines) },
			\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept'
			\ }))

noremap <C-d> :BD<CR>


"noremap <silent> <C-p> :Leaderf file<CR>
noremap <silent> <C-f> :Rg<CR>
noremap <silent> <C-h> :History<CR>
"noremap <C-t> :BTags<CR>
noremap <silent> <C-l> :Lines<CR>
noremap <silent> <C-w> :Buffers<CR>
noremap <silent> <C-a> :History:<CR>
" <<<<<<<<<<



" >>>>>>>>>>
" Vista.vim (View and search LSP symbols, tags in Vim/NeoVim.)
"

" How each level is indented and what to prepend.
" This could make the display more compact or more spacious.
" e.g., more compact: ["▸ ", ""]
" Note: this option only works the LSP executives, doesn't work for `:Vista ctags`.
let g:vista_icon_indent = ["╰─▸ ", "├─▸ "]

" Executive used when opening vista sidebar without specifying it.
" See all the avaliable executives via `:echo g:vista#executives`.
let g:vista_default_executive = 'ctags'

" To enable fzf's preview window set g:vista_fzf_preview.
" The elements of g:vista_fzf_preview will be passed as arguments to fzf#vim#with_preview()
" For example:
let g:vista_fzf_preview = ['right:50%']

" Ensure you have installed some decent font to show these pretty symbols, then you can enbale icon for the kind.
let g:vista#renderer#enable_icon = 1

" The default icons can't be suitable for all the filetypes, you can extend it as you wish.
let g:vista#renderer#icons = {
			\   "function": "\uf794",
			\   "variable": "\uf71b",
			\  }


noremap v :silent! Vista coc<CR>
noremap <c-t> :silent! Vista finder coc<CR>
" <<<<<<<<<<




" vim: set ft=vim:

